using System;
using System.Web.Security;

namespace SoftwareMonkeys.Scriptech.Web.State.Cookies
{
	public class CookieCrypter
	{
		public CookieCrypter ()
		{
		}
		
		static public string Decrypt(string value)
		{
			FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(value);
            
            return ticket.UserData;
		}
		
		static public string Encrypt(string name, string value, DateTime expires)
		{
			// TODO: Check this code
			if (expires <= DateTime.Now)
				expires = DateTime.Now.AddHours(1);
			
			FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, expires, false, value, FormsAuthentication.FormsCookiePath);
			
			string encryptedValue = FormsAuthentication.Encrypt(ticket);
            
            return encryptedValue;
		}
	}
}

